<?php

namespace app\controller\bossManager;

use app\validate\PageValidate;
use app\validate\OpenAppValidate;
use app\service\OpenAppService;

class OpenAppController extends WebBossController{
    public function initValidate(){        
        $this->validate = new OpenAppValidate();
    }

    public function list_action(){  
        $input = $this->check();        
        $page = $this->check('pageInfo',null,(new PageValidate()));        
        $data = OpenAppService::getListInfo($input,$page);
        $res = [];
        foreach($data as $d){
            $tmp  = $d;
            unset($tmp['app_secret']);
            $res[]  = $tmp;
        }
        $total = OpenAppService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$res));    
    }

    public function set_action(){  
        $input = $this->check();
        $res = OpenAppService::edit($input); 
        return self::ok($res);
    }

 
    public function del_action(){ 
        $input = $this->check();
        $res = OpenAppService::delById($input['id']); 
        return self::ok($res);
    }

    public function reset_secret_action(){  
        $input = $this->check('del');
        $res = OpenAppService::resetSecret($input['id']); 
        return self::ok($res);
    }

    public function simple_all_action(){
        $data = OpenAppService::getNativeAll([],['id','app_id','name']);
        return self::ok($data); 
    }
}